<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //i全局
        var arr1 = [];
        for (var i = 0; i < 2; i++) {
            arr1[i] = function () {
                console.log(i);
            }
        }
        arr1[0]();//2
        arr1[1]();//2

        //i局部
        var arr2 = [];
        for (let i = 0; i < 2; i++) {
            arr2[i] = function () {
                console.log(i);
            }
        }
        arr2[0]();//0
        arr2[1]();//1
    </script>
</body>

</html>